import json

from django.shortcuts import render, HttpResponse


def chart_list(request):
    """ 数据分析统计页面 """
    return render(request, 'chart_list.html')


def chart_bar(request):
    """ 柱状图 """
    data_list = ['一级任务', '二级任务']
    x_axis = ['1月', '2月', '3月', '4月', '5月', '6月']
    series_list = [
        {
            'name': '一级任务',
            'type': 'bar',
            'data': [5, 25, 100, 13, 10, 20]
        },
        {
            'name': '二级任务',
            'type': 'bar',
            'data': [6, 15, 23, 0, 30, 80]
        },
    ]

    result = {
        'status': True,
        'data': {
            'series_list': series_list,
            'x_axis': x_axis,
            'data_list': data_list,
        },
    }

    return HttpResponse(json.dumps(result))


def chart_pie(request):
    """ 饼图 """
    series_list = [
        {'value': 1048, 'name': '警令部'},
        {'value': 735, 'name': '政治部'},
        {'value': 1580, 'name': '警保部'},
        {'value': 484, 'name': '业务支队'},
    ]

    result = {
        'status': True,
        'data': series_list,
    }

    return HttpResponse(json.dumps(result))


def chart_line(request):
    """ 折线图 """
    xaxis_list = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    series_list = [820, 932, 901, 934, 1290, 1330, 1320]

    result = {
        'status': True,
        'data': {
            'xaxis': xaxis_list,
            'series_list': series_list,
        }
    }

    return HttpResponse(json.dumps(result))
